#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>

/**
 * 1. 用到DIR类型 dirent结构体、closedir函数、opendir函数、readdir函数等在dirent.h头文件中
 * 2. printf在stdio.h中
 * 3. exit函数在stdlib.h头文件中
 */

int main(int argc, char *argv[]) {
    DIR *dp;
    struct dirent *dirp;

    if ((dp = opendir(argv[1])) == NULL) {
    	printf("error:can not open dir");
    }

    while ((dirp = readdir(dp)) != NULL) {
    	printf("%s\n", dirp->d_name);
    }

    closedir(dp);
    exit(0);
}
